<include file="Public:header" />
<include file="Public:left" />
<style>
    .red{color: white;background: red;border: 1px solid;border-radius: 5px;width: 10px;height: 10px;margin-left: 2px;}
    .customer{padding: 10px 0;border-bottom: 1px #eee solid;text-align: center}
    .blue{color: white;background: deepskyblue}
</style>
<div style="float: left;width: 10%;height: 800px;border-bottom: 1px #eee solid">
    <div style="width: 100%;text-align: center;padding: 15px 0;border-bottom: 1px #eee solid;">咨询客户</div>
    <ul id="chat">

    </ul>
</div>

<iframe id="iframe" data-id="0" src="{:url('chat/mkit',['id' => $id,'touid' => $touid])}" frameborder="0" width="90%" height="800px" style="float: right"></iframe>

</div>
</section>
</body>
<script>

    function getList() {
        var now_id = $('#iframe').attr('data-id');
        $.ajax({
            type: "get",
            url: "{:url('chat/chatList',['id' => $id])}",
            dataType: "json",
            success: function (data) {// console.log(data);
                if(data.code == -1){
                    return false;
                }
                $('#chat').empty();   //清空resText里面的所有内容
                var html = '';
                $.each(data.list, function (commentIndex, comment) {
                    html += '<li style="cursor: pointer;" class="customer';
                    if(now_id == comment.id){
                        html += ' blue';
                    }
                    html += '" onclick="chat('+comment.id+','+comment.goods_id+')">'+comment.nickname;
                    if(comment.num > 0){
                        html += '<span class="red">'+comment.num+'</span>';
                    }
                    html += '</li>';
                });
                $('#chat').html(html);
            }  
        });
    }
    setInterval("getList()", "5000");

    function chat(id,goods_id){
        $('#iframe').attr('src',"{:url('chat/mkit',['id' => $id])}/touid/"+id+"/goods_id/"+goods_id);
        $('#iframe').attr('data-id',id);
        $.ajax({
            type : "POST",
            url: "{:url('chat/readChat')}",
            data: {uid:{$id},touid:id},
            dataType: "json",
            success: function(res){
                console.log(res);
            }
        });
    }



</script>
</html>